package com.aidex.web.controller.risk;

import com.aidex.risk.domain.resultResponse;
import com.aidex.risk.domain.resultRiskResponse;
import com.aidex.risk.domain.syncDeclaration;
import com.aidex.risk.domain.transBaseInfo;
import com.aidex.system.domain.Waybill;
import com.aidex.system.service.WaybillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/tradeRisk")
public class TradeRiskController {

    @Autowired
    private WaybillService waybillService;

    @PostMapping("/syncTrade")
    public resultRiskResponse syncTrade(@Validated @RequestBody syncDeclaration info)   {
        Waybill waybill = new Waybill();
        if(info!=null && info.getData()!=null){
            transBaseInfo item = info.getData().getBaseInfo();
            waybill.setDataSource(info.getFrom());
            waybill.setFlightDate(item.getFlightDatePlan() );
            waybill.setAgentCode(item.getAgentCode() );
            waybill.setBeginFlightDate(item.getFlightNoPlan() );
            waybill.setDestination(item.getDestination() );
            waybill.setDiffProductSn(item.getDiffProductSn() );
            waybill.setEndFlightDate(item.getFlightNoPlan() );
            waybill.setFlightNo(item.getFlightNoPlan() );
            waybill.setGoodsName(item.getGoodsName() );
            waybill.setGoodsType(item.getGoodsType() );
            waybill.setOrganization(item.getOrganization() );
            waybill.setOrigin(item.getOrigin() );
            waybill.setShipper(item.getShipper() );
            waybill.setSpecialGoodsCode(item.getSpecialGoodsCode() );
            waybill.setWaybillNo(item.getAwbNo() );
            waybillService.deleteWaybillByBillno(waybill.getWaybillNo(),waybill.getDataSource());
            waybillService.save(waybill);
        }
        resultRiskResponse result = new resultRiskResponse();
        result.setStatus(200);
        result.setMessage("success");
        result.setTimestamp("2021-10-01 12:00:00");
        return result;
    }

    @PostMapping("/syncTradeALMS")
    //@GetMapping("/syncTradeALMS")
    public resultRiskResponse syncTradeALMS(@Validated @RequestBody syncDeclaration info)   {
        return syncTrade(info);
    }

    @PostMapping("/syncTradeLevel")
    //@GetMapping("/syncTradeLevel")
    public resultResponse syncTradeLevel()   {
        resultResponse result = new resultResponse();
        result.setStatus(200);
        result.setMessage("success");
        result.setTimestamp(1622105424285L);
        return result;
    }

    @PostMapping("/syncEmergencyAirport")
    //@GetMapping("/syncEmergencyAirport")
    public resultResponse syncEmergencyAirport()   {
        resultResponse result = new resultResponse();
        result.setStatus(200);
        result.setMessage("success");
        result.setTimestamp(1622105424285L);
        return result;
    }

    @PostMapping("/syncEmergencyFlight")
    //@GetMapping("/syncEmergencyFlight")
    public resultResponse syncEmergencyFlight()   {
        resultResponse result = new resultResponse();
        result.setStatus(200);
        result.setMessage("success");
        result.setTimestamp(1622105424285L);
        return result;
    }
    @PostMapping("/syncEmergencyGuard")
    //@GetMapping("/syncEmergencyGuard")
    public resultResponse syncEmergencyGuard()   {
        resultResponse result = new resultResponse();
        result.setStatus(200);
        result.setMessage("success");
        result.setTimestamp(1622105424285L);
        return result;
    }
}
